<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <h1>{{msg}}</h1>
        <hr>
        <input type="text" v-model="inputVal">
        <button @click="addData">点击添加数据</button>
        <ul>
            <li v-for="(item,index) of brandList" :key="item.id">
                <span>id:{{item.id}}</span>
                <span>名字:{{item.name}}</span>
                <span>作者:{{item.author}}</span>
                <span>分类:{{item.category}}</span>
                <span>降序:{{item.desc}}</span>
            </li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                msg: "Hello Vue!",
                inputVal: "",
                brandList: ""
            },
            methods: {
                addData() {
                    if (this.inputVal.trim() != "") {
                        let obj = {
                            id: this.brandList[this.brandList.length - 1].id + 1,
                            name: this.inputVal
                        }
                        this.brandList.unshift(obj);
                    }
                }
            },
            created() {
                axios.get("./data/data.json").then(res => {
                    this.brandList = res.data;
                })
            }
        });
    </script>
</body>

</html>